package com.situ.mall.config;

import com.situ.mall.converter.String2DateConverter;
import com.situ.mall.interceptor.LoginInterceptor;
import com.situ.mall.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2DateConverter());
    }

    //配置虚拟路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/D:/mypic/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }


    //这个方法用来配置拦截器，我们写的拦截器只有配置了才起作用
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //白名单
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/page/cart/**", "/cart/**", "/page/order/**", "/order/**");
    }
}